﻿//Load dependencies...
var express = require('express')
,	routes = require('./routes')
,	http = require('http')
,	path = require('path');

var app = express();

//Configure the server...
app.configure(function(){
	app.set('port', process.env.PORT || 3000);
	app.set('views', __dirname + '/views');
	app.set('view engine', 'ejs');
	app.use(express.favicon());
	app.use(express.logger('dev'));
	app.use(express.bodyParser());
	app.use(express.methodOverride());
	app.use(express.cookieParser('your secret here'));
	app.use(express.session());
	app.use(app.router);
	app.use(require('stylus').middleware(__dirname + '/public'));
	app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
	app.use(express.errorHandler());
});

app.use(function(req, res, next){
	res.render('404');
});

//Setup routing table...
app.get('/logout', routes.logout);
app.post('/register', routes.register);

app.get('/password', routes.password);
app.post('/password', routes.passwordReset);
app.get('/recovery/:token', routes.recovery);
app.get('/recovery', routes.redirect);
app.post('/recovery', routes.recoveryPost);

app.get('/', routes.index);
app.post('/', routes.login);

//Start up the server...
http.createServer(app).listen(app.get('port'), function(){
	console.log("Express server listening on port " + app.get('port'));
});
